package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.QuestionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.QuestionQueryObject;
import cn.wolfcode.trip.base.service.IQuestionService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QuestionServiceImpl implements IQuestionService {
    @Autowired
    private QuestionMapper questionMapper;

    public void save(Question question) {
        question.setUser(UserContext.getUser());
        question.setCreatTime(new Date());
        questionMapper.insert(question);
    }



    public PageInfo queryForQuestionList(QuestionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Question> list = questionMapper.selectAll();
        return new PageInfo(list);
    }

    public Question queryForReply(QuestionQueryObject qo) {
        Question question = questionMapper.selectReplyByQuestionId(qo);
        return question;
    }


}
